package com.example.web1;

import com.example.web1.domain.City;
import com.example.web1.mapper.CityMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GreetingController {
    private final CityMapper cityMapper;
    public GreetingController(CityMapper cityMapper) {
        this.cityMapper = cityMapper;
    }

    @GetMapping("/greeting")
    public String greeting(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
        City data = this.cityMapper.findByState("CA");
        model.addAttribute("name", name + data.getName());
        return "greeting";
    }
}